package com.magic.smartcity.view.more.adapters

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.magic.smartcity.R
import com.magic.smartcity.beans.ActivityCategoryList
import com.magic.smartcity.databinding.ItemActivityCategoryBinding

/**
 * @description:
 * @create: Create by Magic on 2022/2/15.
 */
class ActivityHomeCategoryAdapter : RecyclerView.Adapter<ActivityHomeCategoryAdapter.ItemHolder>() {
    private var categoryList = mutableListOf<ActivityCategoryList>()

    private val TAG: String = "ActivityHomeCategoryAdapter"

    class ItemHolder(binding:ItemActivityCategoryBinding) : RecyclerView.ViewHolder(binding.root) {
        val binding = binding
    }

    fun setData(list:List<ActivityCategoryList>){
        categoryList.clear()
        categoryList.addAll(list)
        notifyDataSetChanged()
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
        val binding = DataBindingUtil.inflate<ItemActivityCategoryBinding>(
            LayoutInflater.from(parent.context),
            R.layout.item_activity_category,
            parent,
            false
        )
        return ItemHolder(binding)
    }

    override fun onBindViewHolder(holder: ItemHolder, position: Int) {
        holder.binding.text = categoryList[position].name
    }

    override fun getItemCount() = categoryList.size
}